package com.cxg.fairy.ec.detail;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ui.recycler.DataConverter;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;

import java.util.ArrayList;

/**
 * Created by CFairy
 */

public class StandardDataConverter extends DataConverter {

    @Override
    public ArrayList<MultipleItemEntity> convert() {

        final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");

        if (array != null) {
            final int size = array.size();
            for (int i = 0; i < size; i++) {

                final JSONObject data = array.getJSONObject(i);
                final String name = data.getString("standardName");
                final String value = data.getString("standardValue");

                final MultipleItemEntity entity = MultipleItemEntity.builder()
                        .setField("name", name)
                        .setField("value", value)
                        .build();
                ENTITIES.add(entity);
            }
        }
        return ENTITIES;
    }

    @Override
    public MultipleItemEntity convertHeader() {
        return null;
    }
}
